-
-
Notifications
You must be signed in to change notification settings - Fork 658
fix(system_python): write import paths to generated file instead of using PYTHONPATH #3242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(system_python): write import paths to generated file instead of using PYTHONPATH #3242
Conversation
aignas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave a quick look at this and I think the change is really exciting. I'll do a thorough review once it is ready for review.
|
fyi @mering -- non-shell based bootstrap (still needs a system python, so not our coveted native launcher, but doesn't require you to have a shell installed) @jacky8hyf -- should make bootstrap=script work with site disabled ( |
…into refactor.two.stage.systempython
|
Ok, ready for review |
aignas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool, thank you!
…y_binary (#3495) ### Problem In #3242, it looks like `rules_python` introduced new template placeholders in the bootstrap scripts: `%stage2_bootstrap%` and `%interpreter_args%`. And from what I can tell, also made their successful substitution a requirement. This works totally fine when the caller is calling `rules_python` directly. However, when external repositories (like gRPC's cython) define py_binary using the native rule, these placeholders don't seem to be substituted? The result is that the literal placeholder text ends up in the generated bootstrap scripts, causing `SyntaxError`s or file-not-found errors at runtime ### Fix Detect if the `%stage2_bootstrap%` variable isn't expanded and fallback to `%main%` which IS substituted even for native `py_binary`. For `%interpreter_args%`, wrap it in triple-quotes so it's hopefully always valid Python syntax, then detect the sentinel and default to an empty list. This is a bit hacky, but is fairly non-invasive. --------- Co-authored-by: Richard Levasseur <rlevasseur@google.com>
This changes the system_python bootstrap to use a 2-stage process like the script
bootstrap does. Among other things, this means the import paths are written to
a generated file (
bazel_site_init.py, same as boostrap=script) and sys.pathsetup is performed by the Python code in stage 2.
Since the PYTHONPATH environment variable isn't used, this fixes the problem on
Windows where the value is too long.
This also better unifies the system_python and script based bootstraps because the
same stage 2 code and bazel_site_init code is used.
Along the way, several other improvements:
(stdlib, binary paths, runtime site packages).
-S).interpreter_argsattribute andRULES_PYTHON_ADDITIONAL_INTERPRETER_ARGSenv var work with system_python.main_modulework with system_python.this because their environment doesn't install any shells as a security
precaution).
Fixes #2652